package com.sun.filter;

import javax.servlet.*;
import java.io.IOException;

/**
 * @Author Sun
 * @Date 2020/4/24 17:01
 * @Version 1.0
 */
public class CharacterEncodingFilter implements Filter {

    public void init(FilterConfig filterConfig) throws ServletException {

    }

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
    //    response.setContentType("text/html;charset=utf-8");

        //放行过滤链
        chain.doFilter(request, response);
    }

    public void destroy() {

    }
}
